package org.jeecg.modules.factor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;

import org.jeecg.modules.api.DTO.EmissionFactorQueryDTO;
import org.jeecg.modules.api.VO.EmissionFactorQueryVO;
import org.jeecg.modules.api.VO.EmissionFactorVO;

import org.jeecg.modules.api.entity.CyEmissionFactorCollect;
import org.jeecg.modules.factor.service.ICyEmissionFactorCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

 /**
 * @Description: 碳排因子收藏表
 * @Author: jeecg-boot
 * @Date:   2024-11-11
 * @Version: V1.0
 */
@Api(tags="碳排因子收藏表")
@RestController
@RequestMapping("/CyEmissionFactorCollect/cyEmissionFactorCollect")
@Slf4j
public class CyEmissionFactorCollectController extends JeecgController<CyEmissionFactorCollect, ICyEmissionFactorCollectService> {
	@Autowired
	private ICyEmissionFactorCollectService cyEmissionFactorCollectService;   // 碳排因子收藏service层
	
	/**
	 * 分页列表查询
	 *
	 * @param emissionFactorQueryDTO 碳排因子收藏查询对象
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return pageList 分页列表查询结果集合
	 */
	//@AutoLog(value = "碳排因子收藏表-分页列表查询")
	@ApiOperation(value="碳排因子收藏表-分页列表查询", notes="碳排因子收藏表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(EmissionFactorQueryDTO emissionFactorQueryDTO,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		IPage<EmissionFactorQueryVO> pageList = cyEmissionFactorCollectService.queryPageList(emissionFactorQueryDTO, pageNo, pageSize);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param emissionFactorId 碳排因子id
	 * @return
	 */
	@AutoLog(value = "碳排因子收藏表-添加")
	@ApiOperation(value="碳排因子收藏表-添加", notes="碳排因子收藏表-添加")
	//@RequiresPermissions("org.jeecg.modules.demo:cy_emission_factor_collect:add")
	@GetMapping(value = "/add")
	public Result<String> add(@RequestParam(name="id",required=true) String emissionFactorId) {
		String backMsg = cyEmissionFactorCollectService.add(emissionFactorId);
		return Result.OK(backMsg);
	}

	 /**
	  *   通过id删除
	  *
	  * @param emissionFactorId 碳排因子id
	  * @return
	  */
	 @AutoLog(value = "碳排因子收藏表-通过id删除")
	 @ApiOperation(value="碳排因子收藏表-通过id删除", notes="碳排因子收藏表-通过id删除")
	 //@RequiresPermissions("org.jeecg.modules.demo:cy_emission_factor_collect:delete")
	 @DeleteMapping(value = "/delete")
	 public Result<String> delete(@RequestParam(name="id",required=true) String emissionFactorId) {
		 cyEmissionFactorCollectService.removeByEmissionFactorId(emissionFactorId);
		 return Result.OK("取消收藏!");
	 }

	 /**
	  * 详情
	  *
	  * @param id 碳排因子id
	  * @return emissionFactorVO 碳排因子详情对象
	  */
	 //@AutoLog(value = "碳排因子收藏表-详情")
	 @ApiOperation(value="碳排因子收藏表-详情", notes="碳排因子收藏表-详情")
	 @GetMapping(value = "/queryById")
	 public Result<EmissionFactorVO> queryById(@RequestParam(name="id",required=true) String id) {

		 EmissionFactorVO emissionFactorVO = cyEmissionFactorCollectService.queryById(id);
		 if(emissionFactorVO==null) {
			 return Result.error("未找到对应数据");
		 }
		 return Result.OK(emissionFactorVO);
	 }



	/**
	 *  编辑
	 *
	 * @param cyEmissionFactorCollect 碳排因子收藏对象
	 * @return
	 */
	@AutoLog(value = "碳排因子收藏表-编辑")
	@ApiOperation(value="碳排因子收藏表-编辑", notes="碳排因子收藏表-编辑")
	//@RequiresPermissions("org.jeecg.modules.demo:cy_emission_factor_collect:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody CyEmissionFactorCollect cyEmissionFactorCollect) {
		cyEmissionFactorCollectService.updateById(cyEmissionFactorCollect);
		return Result.OK("编辑成功!");
	}
	

	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "碳排因子收藏表-批量删除")
	@ApiOperation(value="碳排因子收藏表-批量删除", notes="碳排因子收藏表-批量删除")
	//@RequiresPermissions("org.jeecg.modules.demo:cy_emission_factor_collect:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.cyEmissionFactorCollectService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	


    /**
    * 导出excel
    *
    * @param request
    * @param cyEmissionFactorCollect
    */
    //@RequiresPermissions("org.jeecg.modules.demo:cy_emission_factor_collect:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CyEmissionFactorCollect cyEmissionFactorCollect) {

        return super.exportXls(request, cyEmissionFactorCollect, CyEmissionFactorCollect.class, "碳排因子收藏表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("cy_emission_factor_collect:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, CyEmissionFactorCollect.class);
    }

}
